#pragma once
#include "widgets.h"

#include <QWidget>
#include <QPushButton>
class SImage;
class S_WIDGETS_EXPORT SImageButton : public QWidget
{
	enum class ImgType
	{
		kNormal,
		kHover,
		kPressed,
		kDisabled
	};
	Q_OBJECT
public:
	SImageButton(QWidget* parent = nullptr, QString imageId = "");
	~SImageButton() = default;

	void mousePressEvent(QMouseEvent* event);
	void mouseReleaseEvent(QMouseEvent* event);
	void enterEvent(QEvent* event);
	void leaveEvent(QEvent* event);
	void paintEvent(QPaintEvent* event);

	QSize sizeHint() const override;
	void setImg(SImage* img, ImgType type);//TODO: shared_ptr to hold img?
	void setImgId(QString imageId);

	int index() const { return m_index; }
	void setIndex(int val) { m_index = val; }
	void setColor(QColor clrNormal, QColor clrHover, QColor clrPressed, QColor clrDisabled);

signals:
	void clicked(int);
	void enterOrLeaved(bool);

private:
	enum MouseState{
		normal = 0,
		hover,
		pressed,
	};
	SImage* m_imgNormal = nullptr;
	SImage* m_imgHover = nullptr;
	SImage* m_imgPressed = nullptr;
	SImage* m_imgDisabled = nullptr;
	SImage* m_curImg = nullptr;
	int		m_index = 0;

	MouseState m_mouseState;
	bool m_useBgkColor;
	QColor m_clrNormal;
	QColor m_clrHover;
	QColor m_clrPressed;
	QColor m_clrDisabled;
};